package com.bw.skill.mvvm.viewmodel;

import android.widget.ImageView;

import androidx.databinding.ObservableField;

import com.blankj.utilcode.util.LogUtils;
import com.bw.mvvm_common.entity.BaseEntity;
import com.bw.mvvm_common.mvvm.viewmodel.BaseViewModel;
import com.bw.mvvm_common.network.load.LoadImage;
import com.bw.skill.TimeService;
import com.bw.skill.action.SkillAction;
import com.bw.skill.mvvm.model.SecKillModel;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @author KK
 * @description:
 * @date :2021/10/28 10:07
 */
public class SecDetailViewModel extends BaseViewModel<SecKillModel> {

    private TimeService timeService;
    public ObservableField<String> title = new ObservableField<>();
    public ObservableField<String> price = new ObservableField<>();
    String goodsdesc;
    public String goodsicon;
    String goodssku;
   int goodscount;
   int goodsid;
   int userid;
   String goodsprice;
   long nowtimes;
    SkillAction action;
    @Override
    public void oncreate() {
        super.oncreate();
        title.set(goodsdesc);
        price.set(goodssku);
    }

    public void callbundle(String goodsDesc,String goodsIcon,String goodsSku,int goodsCount,int goodsId,String price,int userId,long time ){
        goodsdesc=goodsDesc;
        goodsicon=goodsIcon;
        goodssku=goodsSku;
        goodscount = goodsCount;
        goodsid = goodsId;
        userid = userId;
        goodsprice = price;
        nowtimes = time;


        action = new SkillAction();
        action.action = "ss";
        action.nowTime = nowtimes;
        LogUtils.e("callbundle"+action.nowTime);
        EventBus.getDefault().post(action);

    }

    @Override
    protected void result(BaseEntity baseEntity) {
        if(baseEntity.getMessage().equals("添加购物车成功")){
            showMsg("添加在线购物车成功");
        }
        if(baseEntity.getMessage().equals("存货不足")){
            showMsg("哎呀呀,卖完啦,下次早点哟！");
        }
    }

    HashMap<String, Object> map = new HashMap<>();
    public void requestTime(long nowtime){
        nowtimes = nowtime;
        map.put("time",nowtimes);
        LogUtils.e("requestTime"+nowtimes);
        m.requestAddSecKill(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(this);
    }

    //加入购物车
    public void addShopList(){
        map.put("goodsCount",goodscount);
        map.put("goodsDesc",title.get());
        map.put("goodsIcon",goodsicon);
        map.put("goodsId",goodsid);
        map.put("goodsPrice",goodsprice);
        map.put("goodsSku",price.get());
        map.put("userId",userid);

        action.action = "SecDeatilTime";
        EventBus.getDefault().post(action);



    }

    @Override
    public void onDestory() {
        super.onDestory();
    }


}
